from pyecharts.globals import ThemeType

from demo.dataSource.Data import data

data_xz = data.loc[data['风险地区']!=0,:]
data_xz["风险地区"]
a_1=data_xz["省市地区"].to_list()
b_1=data_xz["风险地区"].to_list()

from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.faker import Faker

pie = (
    Pie(init_opts=opts.InitOpts(theme=ThemeType.LIGHT,width="700px",height="700px",),)
    .add(
        "",[list(z) for z in zip(a_1, b_1)],radius=["40%", "55%"],#饼图的半径
        label_opts=opts.LabelOpts(
            position="outside", #标签的位置
            formatter="{a|{a}}{abg|}\n{hr|}\n {b|{b}: }{c}  {per|{d}%}  ", #标签内容格式器
            background_color="#eee",#文字块背景色
            border_color="#aaa",#图形的描边颜色
            border_width=1,#描边宽度
            border_radius=4,#文字块的圆角
            rich={ #富文本样式
                "a": {"color": "#999", "lineHeight": 22, "align": "center"},
                "abg": {
                    "backgroundColor": "#e3e3e3",
                    "width": "100%",
                    "align": "right",
                    "height": 22,
                    "borderRadius": [4, 4, 0, 0],
                },
                "hr": {
                    "borderColor": "#aaa",
                    "width": "100%",
                    "borderWidth": 0.5,
                    "height": 0,
                },
                "b": {"fontSize": 16, "lineHeight": 33},
                "per": {
                    "color": "#eee",
                    "backgroundColor": "#334455",
                    "padding": [2, 4],
                    "borderRadius": 2,
                },
            },
        ),
    )
    .set_global_opts(title_opts=opts.TitleOpts(
        title="风险地区数量",pos_top= '49%',pos_left='39%',
        title_textstyle_opts=opts.TextStyleOpts(color='#CCFFFF',)),
        )
)
pie.render("../outHTML/pie.html")